package org.sunxin.ch02.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/*
 * 功能说明:Servlet测试
 *
 * Copyright (C)2002－2007 福建鑫诺.All rights reserved. 
 * 
 * HelloWorldServlet.java
 *
 * Original Author: 徐金鹏   创建日期:Sep 5, 2008  时间: 2:50:59 PM
 */
public class HelloWorldServlet implements Servlet {
	private ServletConfig config;

	public void destroy() {
	}

	public ServletConfig getServletConfig() {
		return config;
	}

	/**
	 * 该方法很少使用，因此返回null即可
	 */
	public String getServletInfo() {
		return null;
	}

	/**
	 * ServletConfig对象由容器构造。容器在调用init()方法时，将其作为参数传给Servlet
	 */
	public void init(ServletConfig config) throws ServletException {
		this.config = config;
	}

	public void service(ServletRequest req, ServletResponse res)
			throws ServletException, IOException {
		// 得到PrintWriter对象。Servlet使用输出流来产生响应
		PrintWriter out = res.getWriter();
		// 向客户端发送字符数据
		out.println("Hello World");
		// 关闭输出流
		out.close();
	}
}
